//
//  XQHomeTopCardView.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/19.
//

#import "XQHomeTopCardView.h"
#import "XQHomeTopChooseViewView.h"

@interface XQHomeTopCardView()
@property (nonatomic,strong) UIImageView *bgImageView;
@property (nonatomic,strong) UILabel *topLb;
@property (nonatomic,strong) UILabel *priceLb;
@property (nonatomic,strong) UIImageView *chooseImageView;
@property (nonatomic,strong) XQHomeTopChooseViewView *leftView;
@property (nonatomic,strong) XQHomeTopChooseViewView *rightView;
@end

@implementation XQHomeTopCardView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI {
    [self addSubview:self.bgImageView];
    [self.bgImageView addSubview:self.topLb];
    [self.bgImageView addSubview:self.priceLb];
    [self.bgImageView addSubview:self.chooseImageView];
    [self.chooseImageView addSubview:self.leftView];
    [self.chooseImageView addSubview:self.rightView];
}

- (void)makeConstraints {
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.top.equalTo(@0);
    }];
    [self.topLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@12);
        make.left.equalTo(@24);
    }];
    [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topLb.mas_left);
        make.top.equalTo(self.topLb.mas_bottom).offset(3);
    }];
    [self.chooseImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceLb.mas_bottom).offset(22);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(79);
    }];
    [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@16);
        make.width.mas_equalTo(104);
        make.left.equalTo(@20);
    }];
    [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-36);
        make.width.mas_equalTo(104);
        make.top.equalTo(@16);
    }];
}

#pragma mark - setter

- (void)setDataDic:(NSDictionary *)dataDic {
    NSString *price = dataDic[@"china"];
    NSArray *priceArr = [price componentsSeparatedByString:@" "];
    if (priceArr.count == 2) {
        self.topLb.text = [NSString stringWithFormat:@"Loan amount(%@)",priceArr.firstObject];
        self.priceLb.text =  [XQUnitChange unitChange:priceArr.lastObject];
    }
    
    self.leftView.topLb.text = dataDic[@"conflicts"];
    self.rightView.topLb.text = dataDic[@"encountered"];
    self.leftView.bottomLb.text = dataDic[@"articles"];
    self.rightView.bottomLb.text = dataDic[@"trademark"];
}

- (void)setTopValue:(NSString *)topValue {
    self.topLb.text = topValue;
}

- (void)setPrice:(NSString *)price {
    self.priceLb.text =  [XQUnitChange unitChange:price];
}

- (void)setConflicts:(NSString *)conflicts {
    self.leftView.topLb.text = conflicts;
}

- (void)setEncountered:(NSString *)encountered {
    self.rightView.topLb.text = encountered;
}

- (void)setArticles:(NSString *)articles {
    self.leftView.bottomLb.text = articles;
}

- (void)setTrademark:(NSString *)trademark {
    self.rightView.bottomLb.text = trademark;
}

#pragma mark - lazy

- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.image = [UIImage imageNamed:@"home_card_bg"];
    }
    return _bgImageView;
}

- (UILabel *)topLb {
    if (!_topLb) {
        _topLb = [[UILabel alloc] init];
        _topLb.textColor = [[UIColor colorWithHexString:@"#FFFFFF"] colorWithAlphaComponent:0.5];
        _topLb.font = [UIFont systemFontOfSize:14];
    }
    return  _topLb;
}

- (UILabel *)priceLb {
    if (!_priceLb) {
        _priceLb = [[UILabel alloc] init];
        _priceLb.text = @"0";
        _priceLb.textColor = [UIColor whiteColor];
        _priceLb.font = [UIFont systemFontOfSize:50 weight:UIFontWeightBold];
    }
    return  _priceLb;
}

- (UIImageView *)chooseImageView {
    if (!_chooseImageView) {
        _chooseImageView = [[UIImageView alloc] init];
        _chooseImageView.image = [UIImage imageNamed:@"home_top_choose"];
    }
    return  _chooseImageView;
}

- (XQHomeTopChooseViewView *)leftView {
    if (!_leftView) {
        _leftView = [[XQHomeTopChooseViewView alloc] init];
        _leftView.imageView.image = [UIImage imageNamed:@"home_card_left_t"];
        _leftView.topLb.text = @"Loan term ";
        _leftView.topLb.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
        _leftView.bottomLb.text = @"--";
        _leftView.bottomLb.textColor = [UIColor whiteColor];
    }
    return  _leftView;
}

- (XQHomeTopChooseViewView *)rightView {
    if (!_rightView) {
        _rightView = [[XQHomeTopChooseViewView alloc] init];
        _rightView.imageView.image = [UIImage imageNamed:@"home_card_right_t"];
        _rightView.topLb.text = @"Interest rate";
        _rightView.topLb.textColor = [UIColor colorWithHexString:@"#999999"];
        _rightView.bottomLb.text = @"--";
        _rightView.bottomLb.textColor = [UIColor colorWithHexString:@"#0E1D31"];
    }
    return  _rightView;
}


@end
